extends Node2D

@onready var obj_flag = %ObjFlag
@onready var obj_flag_2 = %ObjFlag2

signal player_stop
signal fall_flag
signal pass_level

var first_tap = true
var rise_flag2 = true

# Called when the node enters the scene tree for the first time.
func _ready():
	obj_flag_2.visible = false


func _on_area_2d_body_entered(body):
	print(body.name + " body_entered!")
	if first_tap:
		# player停止移动
		player_stop.emit()
		fall_flag.emit()
		# 播放降旗动画
		print(body.position)
		var target_position = Vector2(obj_flag.position.x,body.position.y)
		create_tween().tween_property(obj_flag, "position",target_position, 0.1)
		
		target_position.y = -24 
		var player_position = target_position
		player_position.x += 14
		var tween = create_tween().set_parallel(true)
		tween.tween_property(obj_flag, "position",target_position, 0.3)
		tween.tween_property(body, "position",player_position, 0.3)
		tween.tween_callback(emit_pass_level).set_delay(0.5)
		
		first_tap = false

func emit_pass_level():
	pass_level.emit()

func _on_finish_level():
	var target_position = obj_flag_2.position
	target_position.y -= 16
	obj_flag_2.visible = true
	create_tween().tween_property(obj_flag_2, "position",target_position, 0.25)
	
